<?php
/*
 * @Author: 白酒煮饭
 * @Date: 2021-04-01 18:35:06
 * @LastEditors: QQ: 1641763174
 * @LastEditTime: 2021-04-01 20:50:36
 * @Description: file content
 */

//导入数据库
include './config.php';
//$conn转为全局变量
global $conn;

$username = htmlspecialchars($_GET['appName']);
$password = MD5($_GET['pass']);

if (strlen($username) > 6 && strlen($password) > 6) {
    $sql1 = 'SELECT * FROM app_list  WHERE appName=' . $username;
    $result = $conn->query($sql1);
    if ($result->num_rows == 0) {
        $appkey = md5($username . "2021年4月1日18:38:01" . $password);
        $sql = "INSERT INTO `app_list` (`appName`, `passwd`, `appkey`) VALUES ('$username', '$password', '$appkey');";
        if ($conn->multi_query($sql) === true) {
            print_r(json_encode('{"code":200,"msg":"创建成功",data:{"appkey":' . $appkey . '}}'));
        } else {
            print_r(json_encode('{"code":202,"msg":"创建失败"}'));
        }
    } else {
        print_r(json_encode('{"code":203,"msg":"账号重复"}'));
    }
} else {
    print_r(json_encode('{"code":204,"msg":"账号和密码长度必须大于6"}'));
}

$conn->close();
